package org.springcloud.wisdom.springcloud_03_freshman.student.service;

import org.springcloud.wisdom.springcloud_03_freshman.student.dao.GoodsDao;
import org.springcloud.wisdom.springcloud_03_freshman.student.entity.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class GoodsService {
    @Autowired
    GoodsDao goodsDao;

    /**
     * 根据学号来 确保物品被学生领走
     * @param sid 学号
     * @return
     */
    public List<Goods> getGoods(String sid){
        if (sid==null || sid.trim().length()<9 || sid.trim().length()>9){
            return null;
        }
        return goodsDao.getGoodsBySid(sid);
    }

    public  boolean updateGoods(Goods goods){
        if (goods == null){
            return false;
        }
        if (goods.getSid()==null || goods.getSid().trim().length() <9 ||goods.getSid().trim().length()>9){
            return false;
        }
        goods.setReceiveStatus("已领取");
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-hh HH:mm:ss");
        String dataTimeString=sdf.format(new Date());
        goods.setReceiveDt(dataTimeString);
        int res=goodsDao.UpdateGoodsBySid(goods);
        return res>0;
    }
}
